package org.open.cobertura.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class DataUtil {
    /**
     * 计算覆盖率
     * @param value1
     * @param value2
     * @return
     */
    public static double calculateCoverageRatio(int value1,int value2){
        if(value2==0) {
            return 0.0d;
        }
        double dividend = value1;
        double divisor = value2;
        BigDecimal bdDividend = new BigDecimal(Double.toString(dividend));
        BigDecimal bdDivisor = new BigDecimal(Double.toString(divisor));
        BigDecimal result = bdDividend.divide(bdDivisor, 2, RoundingMode.HALF_UP);
        return Double.parseDouble(result.toString());
    }

}
